module.exports = app => {
  return class User extends app.Service {
    * find_wechat_user(uid) {
      //根据从微信服务器返回的openID 查询wehchat_user 用户表中 是否有该用户的信息
      const sql = `SELECT * FROM wechat_user WHERE openID=?`
      const result = yield app.mysql.query(sql, [uid])
      return result

    }
     * find_Recharge_user(uid) {
      //根据从微信服务器返回的openID 查询wehchat_user 用户表中 是否有该用户的信息
      const sql = `SELECT * FROM Recharge_user WHERE openID=?`
      const result = yield app.mysql.query(sql, [uid])
      return result

    }
    //wehchat_user 用户表中  新增用户信息
    * insert_wechat_user(data) {
      const result = yield app.mysql.insert('wechat_user', {
        openID: data.openID,
        nickName: data.nickName,
        gender: data.gender,
        language: data.language,
        city: data.city,
        province: data.province,
        country: data.country,
        avatarUrl: data.avatarUrl,
        time_stamp: data.time_stamp,
        appID: data.appID,
      });
      return result
    } //Recharge_user 用户金额表中  新增用户信息
    * insert_Recharge_user(data) {
      const result = yield app.mysql.insert('Recharge_user', {
        openID: data.openID,
        balance:data.balance,
        total_consumption:data.total_consumption
      });
      return result
    }
    //Landing_History 用户登录历史表中 新增用户登录信息
    * insert_Landing_History(id, name, time) {
      const result = yield app.mysql.insert('Landing_History', {
        openID: id,
        nickName: name,
        lastTime: time
      });
      return result
    }
  }
};